﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace EnsureThat
{
	public delegate void Rule<T>(T obj, string name);
	public static class Ensure
	{
		public static void That<T>(Expression<Func<T>> obj, params Rule<T>[] rules)
		{
			string name = GetMemberName(obj);
			T src = obj.Compile()();
			That<T>(src, name, rules);
		}

		private static void That<T>(T src, string name, params Rule<T>[] rules)
		{
			foreach (var rule in rules)
				rule(src, name);
		}
		static string GetMemberName<T>(Expression<Func<T>> memberExpression)
		{
			return ((MemberExpression)memberExpression.Body).Member.Name;
		}
	}
}
